describe('examples for jquery.override.js', function() {

	// these examples are automatically included as Javascript comment in the
	// released file. See build.xml.
	
	it("EXAMPLE 1: Basic usage", function() {
		// START OF EXAMPLE
		
		// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// EXAMPLE 1: Basic usage

		var tokenizer = {
			tokenize : function(text) {
				return text.split(" ");
			}
		};

		// we expect three tokens: "jQuery", "is", "up-to-date"
		expect(tokenizer.tokenize("jQuery is up-to-date").length).toBe(3);

		// improve the tokenizer: hyphens shall be considered whitespace 
		jQuery.override(tokenizer, {

			tokenize : function($super, text) {
				text = text.replace(/-/g, " ");
				return $super(text);
			}
		
		});

		// we expect five tokens: "jQuery", "is", "up", "to", "date"
		expect(tokenizer.tokenize("jQuery is up-to-date").length).toBe(5);

		// END OF EXAMPLE
	});

	it("EXAMPLE 2: Change the behaviour of a slider widget.", function() {
		// START OF EXAMPLE
		
		// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// EXAMPLE 2: Change the behaviour of a slider widget.

		// define a horizontal slider with a position
		var mySlider = {

			position : 0,

			render : function(newPosition) {
				this.position = newPosition;
				// ... do the rendering now ...
			},

			mouseover : function(mouseEvent) {
				this.render(mouseEvent.pageX);
			}
		};

		// enhance the widget by redefining the method render()
		jQuery.override(mySlider, {

			// the slider shall be positioned ten pixels to the right of the
			// mouse pointer
			render : function($super, newPosition) {
				// you should use $super without the keyword "this"
				$super(newPosition + 10);
			}

		});

		// send a mouse event to the slider
		mySlider.mouseover({
			pageX : 400,
			pageY : 500
		});
		expect(mySlider.position).toBe(410);

		// END OF EXAMPLE
	});

});